﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
		<title>Javascript Utilities</title>
		<link type="text/css" rel="stylesheet" href="../bootstrap.min.css" />
	</head>

	<body>
		<div class="document-contents">
			<p>ASP.NET Boilerplate provides some common utility functions.</p>
			<h4>abp.utils.createNamespace</h4>
			<p>Used to create deep namespaces at once. Assume that we have a base 'abp' namespace and want to create or get 'abp.utils.strings.formatting' namespace. Instead of this:</p>

			<pre lang="js">//Create or get namespace
abp.utils = abp.utils || {};
abp.utils.strings = abp.utils.strings || {};
abp.utils.strings.formatting = abp.utils.strings.formatting || {};

//Add a function to the namespace
abp.utils.strings.formatting.format = function() { ... };</pre>

			<p>We can write like that:</p>

			<pre lang="js">var formatting = abp.utils.createNamespace(abp, 'utils.strings.formatting';

//Add a function to the namespace
formatting.format = function() { ... };</pre>

			<p>This simplifies safely creating deep namespaces. Notice that first argument 
is the root namespace that must be exists.</p>

			<h4>abp.utils.formatString</h4>
			<p>Similar to string.Format in C#. Example usage:</p>
			<pre lang="js">var str = abp.utils.formatString('Hello {0}!', 'World'); //str = 'Hello World!'
var str = abp.utils.formatString('{0} number is {<span lang="tr">1</span>}.', 'Secret', 42); //str = 'Secret number is 42'</pre>
		</div>
	</body>

</html>
